package com.example.server.mapper;

import com.example.server.entity.Lunboplace;
import com.example.server.entity.Place;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface Placemapper {
@Select("select * from location")
   public List<Place> getplace();
@Select("select * from lunbo")
   public List<Lunboplace> getlunboplace();
@Select("select * from location where type = #{type}")
  public   List<Place> findsmall(String type);
@Select("select * from location where city like CONCAT('%', #{searchtext}, '%')")
    List<Place> cityselect(String searchtext);
@Select("select * from location where person_username like CONCAT('%', #{searchtext}, '%')")
    List<Place> personselect(String searchtext);
@Select("select * from location where name like CONCAT('%', #{searchtext}, '%')")
   public List<Place> placeselect(String searchtext);
@Select("select count(*) from location where image_url = #{fileName}")
    boolean selectplace(String fileName);
@Insert("insert into location(name,description,image_url,created_at,person_username,type,city) values(#{locationName},#{description},#{fileName},#{now},#{uploader},#{type},#{city})")
    boolean insertplace(String locationName, String fileName, String type, String city, String uploader, String now, String description);
@Select("select l.* from user_far u INNER JOIN location l ON u.location_id = l.place_id WHERE u.user_id = #{uid}")
    List<Place> uidgetplace(String uid);
@Select("select count(*) from location")
    int select();
@Delete("delete from location where place_id = #{id}")
    int delete(int id);
    @Insert("INSERT INTO lunbo(location_id, image_url, Lname) " +
            "SELECT place_id, image_url, name " +
            "FROM location " +
            "WHERE place_id = #{id}")
    boolean addlunbo(int id);
@Delete("delete from lunbo where location_id = #{id}")
    int deletelunbo(String id);
@Select("select count(*) from lunbo where location_id = #{id}")
    int selectlunboplace(int id);
}
